package com.stark.asm.web.action.send;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.stark.asm.common.util.CommonConstant;
import com.stark.asm.common.util.action.BaseAction;
import com.stark.asm.common.util.page.Result;
import com.stark.asm.domain.carrier.query.CarrierQuery;
import com.stark.asm.domain.send.Send;
import com.stark.asm.domain.send.query.SendQuery;
import com.stark.asm.domain.send.query.SendTypeQuery;
import com.stark.asm.service.carrier.CarrierService;
import com.stark.asm.service.send.SendService;
import com.stark.asm.service.send.SendTypeService;


/**
 * Send information  action
 * @author WangYue
 *
 */
public class SendAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final static Log log = LogFactory.getLog(SendAction.class);
    
    /**
     * Send information Service
     */
    private SendService SendService;
    /**
     * Send information query value class
     */
    private SendQuery SendQuery;
    
    /**
     * Send information
     */
    private Send Send;
    
    /**
     *  Page size 
     */
    private int pageSize = 20;
    /**
     * Carrier information Service
     */
    
    private CarrierService carrierService;
    
    /**
     * Send type information Service
     */
    private SendTypeService sendTypeService;

    /**
     * To Send information list page
     *
     * @return
     */
    public String sendMain() {
        if (null == SendQuery) {
            SendQuery = new SendQuery();
        }
        SendQuery.setYn(CommonConstant.YN_NO_DELETE);     // not delete
        Result result = SendService.querySendListPageByQueryBean(SendQuery, page, pageSize);
        toVm(result);
        return "sendMain";
    }

    /**
     * 
     * To add Send information page
     * @return
     */
    public String toAddSend() {
    	
    	SendTypeQuery sendTypeQuery = new SendTypeQuery(); //new carrierQuery object
    	sendTypeQuery.setYn(CommonConstant.YN_NO_DELETE);
    	Result sendTypeResult =sendTypeService.querySendTypeListByQueryBean(sendTypeQuery); //call querySendTypeListByQueryBean()method
    	
    	CarrierQuery carrierQuery = new CarrierQuery(); //new carrierQuery object
    	carrierQuery.setYn(CommonConstant.YN_NO_DELETE);
    	Result carrierResult =carrierService.queryCarrierListByQueryBean(carrierQuery); //call queryCarrierListByQueryBean()method
    	this.toVm(sendTypeResult);
        this.toVm(carrierResult);
        return "toAddSend";
    }

    /**
     * 
     * To update Send information page
     * @return
     */
    public String toUpdateSend() {
    	
    	SendTypeQuery sendTypeQuery = new SendTypeQuery(); //new carrierQuery object
    	sendTypeQuery.setYn(CommonConstant.YN_NO_DELETE);
    	Result sendTypeResult =sendTypeService.querySendTypeListByQueryBean(sendTypeQuery); //call querySendTypeListByQueryBean()method
    	
    	CarrierQuery carrierQuery = new CarrierQuery(); //new carrierQuery object
    	carrierQuery.setYn(CommonConstant.YN_NO_DELETE);
    	Result carrierResult =carrierService.queryCarrierListByQueryBean(carrierQuery); //call queryCarrierListByQueryBean()method
    	this.toVm(sendTypeResult);
        this.toVm(carrierResult);
    	
        if (null != Send) {
            // get Send information by id
            Result result = SendService.getSendById(Send.getId());
            toVm(result);
        } else {
            log.error("SendAction!toUpdateSend() error!");
        }
        return "toUpdateSend";
    }
    
    /**
     * 
     * To update Send information page
     * @return
     */
    public String toDeleteSend() {
    	
    	SendTypeQuery sendTypeQuery = new SendTypeQuery(); //new carrierQuery object
    	sendTypeQuery.setYn(CommonConstant.YN_NO_DELETE);
    	Result sendTypeResult =sendTypeService.querySendTypeListByQueryBean(sendTypeQuery); //call querySendTypeListByQueryBean()method
    	
    	CarrierQuery carrierQuery = new CarrierQuery(); //new carrierQuery object
    	carrierQuery.setYn(CommonConstant.YN_NO_DELETE);
    	Result carrierResult =carrierService.queryCarrierListByQueryBean(carrierQuery); //call queryCarrierListByQueryBean()method
    	this.toVm(sendTypeResult);
        this.toVm(carrierResult);
    	
        if (null != Send) {
            // get Send information by id
            Result result = SendService.getSendById(Send.getId());
            toVm(result);
        } else {
            log.error("SendAction!toDeleteSend() error!");
        }
        return "toDeleteSend";
    }


	public SendService getSendService() {
		return SendService;
	}

	public void setSendService(SendService sendService) {
		SendService = sendService;
	}

	public SendQuery getSendQuery() {
		return SendQuery;
	}

	public void setSendQuery(SendQuery sendQuery) {
		SendQuery = sendQuery;
	}

	public Send getSend() {
		return Send;
	}

	public void setSend(Send send) {
		Send = send;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setCarrierService(CarrierService carrierService) {
		this.carrierService = carrierService;
	}

	public SendTypeService getSendTypeService() {
		return sendTypeService;
	}

	public void setSendTypeService(SendTypeService sendTypeService) {
		this.sendTypeService = sendTypeService;
	}

	public CarrierService getCarrierService() {
		return carrierService;
	}
	
	

  
}
